package cn.hml.org.service.impl;

import cn.hml.basic.util.PageList;
import cn.hml.org.domain.Employee;
import cn.hml.org.mapper.EmployeeMapper;
import cn.hml.org.query.EmployeeQuery;
import cn.hml.org.service.IEmployeeService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
@Service
@Transactional(readOnly = true,propagation = Propagation.SUPPORTS)
public class EmployeeServiceImpl implements IEmployeeService {
    private EmployeeMapper employeeMapper;

    @Override
    public List<Employee> loadAll() {
        return employeeMapper.loadAll();
    }

    @Override
    public Employee loadById(Long id) {
        return employeeMapper.loadById(id);
    }
    @Transactional
    @Override
    public void sava(Employee employee) {
        employeeMapper.sava(employee);

    }
    @Transactional
    @Override
    public void update(Employee employee) {
        employeeMapper.update(employee);

    }
    @Transactional
    @Override
    public void del(Long id) {
        employeeMapper.del(id);

    }

    @Override
    public PageList<Employee> queryPage(EmployeeQuery employeeQuery) {
        //查询总数量前端计算分页栏
        Integer totals = employeeMapper.queryCount(employeeQuery);
        if (totals==null){
            return new PageList<>();
        }
        //查询当前页的分页数据 前端展示当前页的数据
        List<Employee> data = employeeMapper.querydata(employeeQuery);
        return new PageList<>(totals,data);
    }


}
